<?php
/**
 * crcl/base
 *
 * Copyright 2013 CRCL - André Sabosch - info@crcl.de
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace crcl\base\mvc\request;

/**
 * On CLI, call: php index.php --call user/logout (--method POST) (--view json)
 */
interface IConsole
{
}

class ContainerConsole extends Base implements IConsole
{
  const PARAM_CALL   = 'call';
  const PARAM_METHOD = 'method';
  const PARAM_VIEW   = 'view';
  const PARAM_XHTML  = 'xhtml';

  public function getCall()
  {
    try
    {
      $sResult = \crcl\base\Console::getParam(self::PARAM_CALL);
    }
    catch (\Exception $e)
    {
      $sResult = self::DEFAULT_CALL;
    }

    //we dont like the params
    $sResult = $this->cutParamsAndFragment($sResult);
    $sResult = $this->cutExtension($sResult);

    return $sResult;
  }

  public function getMethod()
  {
    $sResult = self::DEFAULT_METHOD;
    try
    {
      $sTemp = \crcl\base\Console::getParam(self::PARAM_METHOD);
      if (!empty($sTemp))
      {
        $sResult = $sTemp;
      }
    }
    catch (\Exception $e)
    {
    }
    return $sResult;
  }

  public function getView()
  {
    $sResult = self::DEFAULT_VIEW;
    try
    {
      $sTemp = \crcl\base\Console::getParam(self::PARAM_VIEW);
      if (!empty($sTemp))
      {
        $sResult = $sTemp;
      }
    }
    catch (\Exception $e)
    {
    }
    return $sResult;
  }
  
  public function hasXhtml()
  {
    $bResult = \FALSE;
    try
    {
      $sTemp = \crcl\base\Console::getParam(self::PARAM_XHTML);
      if ($sTemp == 'yes')
      {
        $bResult = \TRUE;
      }
    }
    catch (\Exception $e)
    {
    }
    return $bResult;
  }
}